import { createRouter, createWebHistory } from 'vue-router'
import VueCookie from "vue-cookie";
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/index',
      name: 'Home',
      component: () => import('@/views/home'),
      redirect:'/sindex',
      children: [
        {
          path: '/sindex',
          component: () => import('@/views/login/user')
        },
        {
          path: '/deparment',
          name: 'DeptList',
          component: () => import('@/views/admin/dept')
        },
        {
          path: '/registLevel',
          name: 'registLevelList',
          component: () => import('@/views/admin/registLevel')
        },
        {
          path: '/employee',
          name: 'emplyeeList',
          component: () => import('@/views/admin/emp')
        },
        {
          path: '/register',
          name: 'Register',
          component: () => import('@/views/caiwu/register')
        },
        {
          path: '/register/list',
          name: 'Register2',
          component: () => import('@/views/caiwu/register/list')
        },
        {
          path: '/medical',
          name: 'Medical',
          component: () => import('@/views/doctor/medical')
        },
        {
          path: '/check',
          name: 'Check',
          component: () => import('@/views/doctor/check')
        },
        {
          path: '/inspection',
          name: 'Inspection',
          component: () => import('@/views/doctor/inspection')
        },
        {
          path: '/pay',
          name: 'Pay',
          component: () => import('@/views/caiwu/pay')
        },
        {
          path: '/check/list',
          name: 'CheckList',
          component: () => import('@/views/check/list')
        },
        {
          path: '/inspection/list',
          name: 'InspectionList',
          component: () => import('@/views/inspection/list')
        },
        {
          path: '/register/records',
          name: 'RegisterRecords',
          component: () => import('@/views/caiwu/register/records')
        },
        {
          path: '/check/result',
          name: 'CheckResult',
          component: () => import('@/views/doctor/check/result')
        },
        {
          path: '/inspection/result',
          name: 'InspectionResult',
          component: () => import('@/views/doctor/inspection/result')
        },
        {
          path: '/doctor/quezhen',
          name: 'DoctorQuezhen',
          component: () => import('@/views/doctor/medical/quezhen')
        },
        {
          path: '/doctor/prescription',
          name: 'Prescription',
          component: () => import('@/views/doctor/prescription')
        },
        {
          path: '/drug',
          name: 'Drug',
          component: () => import('@/views/doctor/drug')
        },
        {
          path: '/user',
          name: 'User',
          component: () => import('@/views/login/user')
        },
        {
          path: '/drugList',
          name: 'DrugList',
          component: () => import('@/views/doctor/drugList')
        }
      ]
    },
    {
      path:'/login',
      name:'Login',
      component:()=>import('@/views/login')
    }
  ]
})
router.beforeEach((to,from,next)=>{
  const token=VueCookie.get('token')
  if (to.fullPath==='/login' || token){
    next()
    return
  }
  next('/login')
})
export default router
